<template>
  <div class="forbidden-page">
    <div class="decoration">
      <div class="triangle triangle-1"></div>
      <div class="triangle triangle-2"></div>
      <div class="triangle triangle-3"></div>
      <div class="warning" v-for="symbol in warningSymbols" :key="symbol">
        {{ symbol }}
      </div>
    </div>

    <div class="container" ref="containerRef">
      <div class="lock-icon">🔒</div>
      <div class="error-code" ref="errorCodeRef" @click="triggerShake">403</div>
      <h1 class="error-title">权限不足</h1>
      <p class="error-message">
        您没有访问此页面的权限。<br />
        请联系系统管理员获取相应权限。
      </p>
      <button class="btn" @click="goBack" :disabled="isRedirecting">
        {{ isRedirecting ? '正在返回...' : '返回' }}
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'

// 响应式数据
const containerRef = ref(null)
const errorCodeRef = ref(null)
const isRedirecting = ref(false)
const router = useRouter()

// 警告符号
const warningSymbols = ['⚠', '🔒', '⛔']

// 鼠标移动视差效果
const handleMouseMove = (e) => {
  if (!containerRef.value) return
  const x = (window.innerWidth - e.pageX) / 150
  const y = (window.innerHeight - e.pageY) / 150
  containerRef.value.style.transform = `translate(${x}px, ${y}px)`
}

// 触发震动效果
const triggerShake = () => {
  if (!errorCodeRef.value) return
  errorCodeRef.value.style.animation = 'none'

  setTimeout(() => {
    if (errorCodeRef.value) {
      errorCodeRef.value.style.animation = 'shake 0.5s'
    }
  }, 10)

  setTimeout(() => {
    if (errorCodeRef.value) {
      errorCodeRef.value.style.animation = 'shake 3s infinite'
    }
  }, 500)
}

// 返回首页
const goBack = () => {
  isRedirecting.value = true
  setTimeout(() => {
    router.back()
  }, 800)
}

// 检测是否为触摸设备
const isTouchDevice = () => {
  return 'ontouchstart' in window || navigator.maxTouchPoints > 0
}

// 组件挂载
onMounted(() => {
  if (!isTouchDevice()) {
    window.addEventListener('mousemove', handleMouseMove)
  }
})

// 组件卸载
onUnmounted(() => {
  window.removeEventListener('mousemove', handleMouseMove)
})
</script>

<style lang="scss" scoped>
.forbidden-page {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans',
    'Helvetica Neue', sans-serif;
  overflow: hidden;
  position: relative;
  padding: 20px;
  background: linear-gradient(135deg, #2c3e50, #4a6491);

  .container {
    text-align: center;
    z-index: 10;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    width: 100%;
    max-width: 400px;
    position: relative;
    transition: transform 0.1s ease;

    .lock-icon {
      font-size: 3rem;
      margin-bottom: 1rem;
      color: #ff6b6b;
      animation: lock-pulse 2s infinite;
    }

    .error-code {
      font-size: 8rem;
      font-weight: 800;
      color: rgba(255, 255, 255, 0.9);
      text-shadow: 0 0 15px rgba(255, 100, 100, 0.6);
      margin-bottom: -1rem;
      position: relative;
      animation: shake 3s infinite;
      line-height: 1;
      cursor: pointer;
      transition: all 0.1s ease;

      &::before {
        content: '403';
        position: absolute;
        top: 0;
        left: 0;
        color: transparent;
        text-shadow: 0 0 20px rgba(255, 50, 50, 0.8);
        z-index: -1;
        animation: warning 2s infinite;
      }
    }

    .error-title {
      font-size: 1.8rem;
      color: #ff9a9e;
      margin-bottom: 1rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      font-weight: 600;
    }

    .error-message {
      font-size: 1rem;
      color: rgba(255, 255, 255, 0.85);
      margin-bottom: 1.5rem;
      line-height: 1.6;
    }

    .btn {
      display: inline-block;
      padding: 14px 25px;
      background: linear-gradient(45deg, #3498db, #8e44ad);
      color: white;
      text-decoration: none;
      border-radius: 50px;
      font-weight: 600;
      letter-spacing: 1px;
      transition: all 0.3s ease;
      box-shadow: 0 4px 15px rgba(52, 152, 219, 0.4);
      border: none;
      cursor: pointer;
      font-size: 1rem;
      width: 100%;
      max-width: 200px;
      margin: 0 auto;

      &:hover:not(:disabled) {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(52, 152, 219, 0.6);
      }

      &:active:not(:disabled) {
        transform: translateY(1px);
      }

      &:disabled {
        opacity: 0.8;
        cursor: not-allowed;
      }
    }
  }

  .decoration {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;

    .triangle {
      position: absolute;
      border-radius: 5px;
      background: linear-gradient(45deg, rgba(255, 107, 107, 0.1), transparent);
      transform: rotate(45deg);

      &-1 {
        width: 150px;
        height: 150px;
        top: -75px;
        right: -75px;
      }

      &-2 {
        width: 100px;
        height: 100px;
        bottom: -50px;
        left: -50px;
      }

      &-3 {
        width: 80px;
        height: 80px;
        top: 20%;
        left: 5%;
      }
    }

    .warning {
      position: absolute;
      font-size: 1.8rem;
      color: rgba(255, 107, 107, 0.2);
      animation: warning-float 6s infinite ease-in-out;

      &:nth-child(1) {
        top: 10%;
        left: 5%;
        animation-delay: 0s;
      }

      &:nth-child(2) {
        top: 70%;
        right: 8%;
        animation-delay: 2s;
      }

      &:nth-child(3) {
        bottom: 20%;
        left: 12%;
        animation-delay: 4s;
      }
    }
  }

  // 动画定义
  @keyframes shake {
    0%,
    100% {
      transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
      transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
      transform: translateX(5px);
    }
  }

  @keyframes warning {
    0%,
    100% {
      opacity: 0.8;
    }

    50% {
      opacity: 0.4;
    }
  }

  @keyframes lock-pulse {
    0%,
    100% {
      transform: scale(1);
    }

    50% {
      transform: scale(1.1);
    }
  }

  @keyframes warning-float {
    0% {
      transform: translateY(0) rotate(0deg);
    }

    50% {
      transform: translateY(-20px) rotate(15deg);
    }

    100% {
      transform: translateY(0) rotate(0deg);
    }
  }

  // 响应式设计
  @media (max-width: 480px) {
    .container {
      padding: 1.2rem;

      .error-code {
        font-size: 7rem;
      }

      .error-title {
        font-size: 1.5rem;
      }

      .error-message {
        font-size: 0.9rem;
      }
    }
  }

  @media (max-width: 360px) {
    .container {
      .error-code {
        font-size: 6rem;
      }

      .error-title {
        font-size: 1.3rem;
      }
    }
  }
}
</style>
